package com.ruoyi.refundInfo.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.ruoyi.businessOrder.domain.BusinessOrder;
import com.ruoyi.businessOrder.domain.dto.RefundAuditDto;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.refundInfo.mapper.RefundInfoMapper;
import com.ruoyi.refundInfo.domain.RefundInfo;
import com.ruoyi.refundInfo.service.IRefundInfoService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 退款信息日志管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-02
 */
@Service
public class RefundInfoServiceImpl implements IRefundInfoService 
{
    @Autowired
    private RefundInfoMapper refundInfoMapper;

    /**
     * 查询退款信息日志管理
     * 
     * @param refundId 退款信息日志管理主键
     * @return 退款信息日志管理
     */
    @Override
    public RefundInfo selectRefundInfoByRefundId(Long refundId)
    {
        return refundInfoMapper.selectRefundInfoByRefundId(refundId);
    }

    /**
     * 查询退款信息日志管理列表
     * 
     * @param refundInfo 退款信息日志管理
     * @return 退款信息日志管理
     */
    @Override
    public List<RefundInfo> selectRefundInfoList(RefundInfo refundInfo)
    {
        return refundInfoMapper.selectRefundInfoList(refundInfo);
    }

    /**
     * 新增退款信息日志管理
     * 
     * @param refundInfo 退款信息日志管理
     * @return 结果
     */
    @Override
    public int insertRefundInfo(RefundInfo refundInfo)
    {

        // 添加创建人
        refundInfo.setCreateBy(SecurityUtils.getUsername());
        // 添加创建时间
        refundInfo.setCreateTime(DateUtils.getNowDate());
        return refundInfoMapper.insertRefundInfo(refundInfo);
    }

    /**
     * 修改退款信息日志管理
     * 
     * @param refundInfo 退款信息日志管理
     * @return 结果
     */
    @Override
    public int updateRefundInfo(RefundInfo refundInfo)
    {
        refundInfo.setUpdateBy(SecurityUtils.getUsername());
        refundInfo.setUpdateTime(DateUtils.getNowDate());
        return refundInfoMapper.updateRefundInfo(refundInfo);
    }

    /**
     * 批量删除退款信息日志管理
     * 
     * @param refundIds 需要删除的退款信息日志管理主键
     * @return 结果
     */
    @Override
    public int deleteRefundInfoByRefundIds(Long[] refundIds)
    {
        return refundInfoMapper.deleteRefundInfoByRefundIds(refundIds);
    }

    /**
     * 删除退款信息日志管理信息
     * 
     * @param refundId 退款信息日志管理主键
     * @return 结果
     */
    @Override
    public int deleteRefundInfoByRefundId(Long refundId)
    {
        return refundInfoMapper.deleteRefundInfoByRefundId(refundId);
    }

    /**
     * 修改退款信息日志管理
     *
     */
    @Override
    public void updateRefund(String content) {
        // 将json字符串转为Map
        Map<String, String> map = JSON.parseObject(content, Map.class);

    }

    /**
     * 根据订单id查询退款信息
     *
     */
    @Override
    public RefundInfo selectByOrderId(Long orderId) {

        return refundInfoMapper.selectRefundInfoByOrderId(orderId);
    }

    /**
     * 根据订单id查询正在退款的订单
     *
     */
    @Override
    public List<RefundInfo> selectActiveRefundsByOrderId(Long orderId) {
        return refundInfoMapper.selectActiveRefundsByOrderId(orderId);
    }

    /**
     * 根据订单id查询最新的退款信息
     *
     */
    @Override
    public RefundInfo getLatestRefundByOrderId(Long orderId) {
        return refundInfoMapper.getLatestRefundByOrderId(orderId);
    }

    /**
     * 根据商品订单id查询正在退款的订单
     *
     */
    @Override
    public List<RefundInfo> selectActiveRefundsByGoodsOrderId(Long goodsOrderId) {
        return refundInfoMapper.selectActiveRefundsByGoodsOrderId(goodsOrderId);
    }

    /**
     * 根据商品订单id查询最新的退款信息
     *
     */
    @Override
    public RefundInfo getLatestRefundByGoodsOrderId(Long goodsOrderId) {
        return refundInfoMapper.getLatestRefundByGoodsOrderId(goodsOrderId);
    }

}
